package com.mall.market.controller;

import com.mall.commons.utils.CommonResult;
import com.mall.market.service.SmsHomeBrandService;
import com.mall.model.domain.SmsHomeBrand;
import com.mall.model.vo.CommonPage;
import com.mall.model.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/home/brand")
public class SmsHomeBrandController {

    @Autowired
    private SmsHomeBrandService smsHomeBrandService;

    /**
     * 分页查询推荐品牌
     *
     * @param brandName
     * @param pageNum
     * @param pageSize
     * @param recommendStatus
     * @return
     */
    @GetMapping("/list")
    public CommonResult HomeBrandList(String brandName, Integer pageNum, Integer pageSize, Integer recommendStatus) {
        CommonPage pageResult = smsHomeBrandService.HomeBrandList(brandName, pageNum, pageSize, recommendStatus);
        return CommonResult.success(pageResult, "");
    }

    /**
     * 添加品牌
     * @param smsHomeBrand
     * @return
     */
    @PostMapping("/create")
    public CommonResult addBrand(@RequestBody SmsHomeBrand smsHomeBrand) {
        smsHomeBrandService.addBrand(smsHomeBrand);
        return CommonResult.success("添加成功");
    }

    /**
     * 批量删除品牌
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public CommonResult removeBrand(@RequestParam List<Integer> ids) {
        smsHomeBrandService.removeBrand(ids);
        return CommonResult.success("删除成功");
    }

    /**
     *批量修改品牌推荐状态
     * @param ids
     * @param recommendStatus
     * @return
     */
    @PostMapping("/update/recommendStatus")
    public CommonResult updateBrandStatus(@RequestParam List<Integer> ids, Integer recommendStatus) {
        smsHomeBrandService.updateBrandStatus(ids, recommendStatus);
        return CommonResult.success("修改成功");
    }

    /**
     * 修改推荐品牌排序
     * @param id
     * @param sort
     * @return
     */
    @PostMapping("update/sort/{id}")
    public CommonResult updateSort(@PathVariable("id") Integer id, Integer sort) {
        smsHomeBrandService.updateSort(id, sort);
        return CommonResult.success("修改成功");
    }
}
